<template>
  <div class="box" :style="{ background: `url(${bg})` }">
    <div class="box-left">
      <div class="box-left-card">
        <section>
          <div>较上日+ {{ store.ChinaAdd.localConfirm }}</div>
          <div>{{ store.ChinaTotal.localConfirmTotal }}</div>
          <div>本土现有确诊</div>
        </section>
        <section>
          <div>较上日+ {{ store.ChinaAdd.localNow }}</div>
          <div>{{ store.ChinaTotal.localNowTotal }}</div>
          <div>现有确诊</div>
        </section>
        <section>
          <div>较上日+ {{ store.ChinaAdd.addLocalConfirm }}</div>
          <div>{{ store.ChinaTotal.localConfirmTotal }}</div>
          <div>累计确诊</div>
        </section>
        <section>
          <div>较上日+ {{ store.ChinaAdd.noInfect }}</div>
          <div>{{ store.ChinaTotal.noInfectTotal }}</div>
          <div>无症状感染者</div>
        </section>
        <section>
          <div>较上日+ {{ store.ChinaAdd.input }}</div>
          <div>{{ store.ChinaTotal.inputTotal }}</div>
          <div>境外输入</div>
        </section>
        <section>
          <div>较上日+ {{ store.ChinaAdd.addDead }}</div>
          <div>{{ store.ChinaTotal.addDeadTotal }}</div>
          <div>累计死亡</div>
        </section>

      </div>
      <div class="box-left-pie" ref="pieChart">
      </div>
      <div class="box-left-line" ref="pieChart">
      </div>
    </div>
    <div id="chinas" class="box-center">
    </div>
    <div class="box-right" style="color: white;">
      <table cellspacing="0" border="1" class="table">
        <thead>
          <tr>
            <th>地区</th>
            <th>新增确诊</th>
            <th>累计确诊</th>
            <th>治愈</th>
            <th>死亡</th>
          </tr>
        </thead>
        <transition-group enter-active-class="animate__animated animate__fadeIn" tag="tbody">
          <tr :key="item.cityName" v-for="(item, index) in store.CityArrayList">
            <td align="center">{{ item.cityName }}</td>
            <td align="center">{{ item.cityData.confirmed }}</td>
            <td align="center">{{ item.cityData.total }}</td>
            <td align="center">{{ item.cityData.recovered }}</td>
            <td align="center">{{ item.cityData.deaths }}</td>
          </tr>
        </transition-group>
      </table>

    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, nextTick } from 'vue';
import bg from '@/assets/bg.jpg';
import { useStore } from './stores';
import { onMounted } from 'vue';
import * as echarts from 'echarts';
import "@/assets/china"
import { geoCoorMap } from './assets/geoMap';
import "animate.css"
// import type { RootObject, ProvinceArrayList, CityArrayList, CityData } from "@/stores/type"

const store = useStore();
store.getList();


const initCharts = async () => {
  // await nextTick();
  // console.log(store.list);
  const city = store.provinceArrayList;
  store.CityArrayList = city[8].cityArrayList;
  const data = city.map((item: any) => {
    return {
      name: item.provinceName,
      value: geoCoorMap[item.provinceName]?.concat(item.total),
      children: item.cityArrayList,
    }
  })
  const myChart = echarts.init(document.querySelector('#chinas') as HTMLElement)

  myChart.setOption({
    // backgroundColor: "black",
    geo: {
      map: "china",
      aspectScale: 0.8,
      layoutCenter: ["50%", "50%"],
      layoutSize: "120%",
      itemStyle: {
        // normal: {
        areaColor: {
          type: "linear-gradient",
          x: 0,
          y: 1200,
          x2: 1000,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: "#152E6E", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "#0673AD", // 50% 处的颜色
            },
          ],
          global: true, // 缺省为 false
        },
        shadowColor: "#0f5d9d",
        shadowOffsetX: 0,
        shadowOffsetY: 15,
        opacity: 0.5,
        // },

      },
      emphasis: {
        areaColor: "#0f5d9d",
      },
      regions: [
        {
          name: "南海诸岛",
          itemStyle: {
            areaColor: "rgba(0, 10, 52, 1)",
            borderColor: "rgba(0, 10, 52, 1)",
            // normal: {
            opacity: 0,
            label: {
              show: false,
              color: "#009cc9",
            },
          },
          // },
          label: {
            show: false,
            color: "#FFFFFF",
            fontSize: 12,
          },
        },
      ],
    },
    series: [
      {
        type: "map",
        // selectedMode: "multiple",
        map: "china",
        aspectScale: 0.8,
        layoutCenter: ["50%", "50%"], //地图位置
        layoutSize: "120%",
        zoom: 1, //当前视角的缩放比例
        // roam: true, //是否开启平游或缩放
        scaleLimit: {
          //滚轮缩放的极限控制
          min: 1,
          max: 2,
        },
        label: {
          show: true,
          color: "#FFFFFF",
          fontSize: 16,
        },
        itemStyle: {
          // normal: {
          areaColor: "#0c3653",
          borderColor: "#1cccff",
          borderWidth: 1.8,
          // },
        },
        emphasis: {
          areaColor: "#56b1da",
          label: {
            show: true,
            color: "#fff",
          },
        },
        data: data,
      },
      {
        type: 'scatter',
        coordinateSystem: 'geo',
        //   symbol: 'image://http://ssq168.shupf.cn/data/biaoji.png',
        // symbolSize: [30,120],
        // symbolOffset:[0, '-40%'] ,
        symbol: 'pin',
        symbolSize: [45, 45],
        label: {
          // normal: {
          show: true,
          color: '#fff',
          formatter(value: any) {
            return value.data.value[2]
          }
          // },
        },
        itemStyle: {
          // normal: {
          color: '#1cccff', //标志颜色
          // }
        },
        data: data,
      },
    ],
  })

  myChart.on('click', (e: any) => {
    // console.log(e);
    store.CityArrayList = e.data.children;
    // console.log(e);
  })
}
const initPie = async () => {
  // console.log(store.provinceArrayDetailList)
  const myChart = echarts.init(document.querySelector('.box-left-pie') as HTMLElement)
  myChart.setOption({
    backgroundColor: '#223651',
    tooltip: {
      trigger: 'item'
    },
    series: [
      {
        // name: '',
        type: 'pie',
        radius: ['40%', '70%'],
        itemStyle: {
          borderRadius: 4,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: true,
          // position: 'center',
          fontWeight: 'bold'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 15,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: true, // 显示引导线
          length: 10, // 引导线长度距离
        },
        data: store.provinceArrayDetailList.map(v => {
          return {
            name: v.provinceName,
            value: v.total
          }
        })
      }
    ]
  })
}
const initLine = async () => {
  const myChart = echarts.init(document.querySelector('.box-left-line') as HTMLElement)
  myChart.setOption({
    backgroundColor: '#223651',
    xAxis: {
      type: 'category',
      data: store.provinceArrayDetailList2.map(v => {
        return v.provinceName
      }),
      axisLine: {
        lineStyle: {
          color: '#fff'
        }
      }
    },
    yAxis: {
      type: 'value',
      axisLine: {
        lineStyle: {
          color: '#fff'
        }
      }
    },
    label: {
      show: true,
      position: 'top',
      color: '#fff'
    },
    tooltip: {
      trigger: 'axis'
    },
    series: [
      {
        data: store.provinceArrayDetailList2.map(v => {
          return v.total
        }),
        type: 'line',
        smooth: true
      }
    ]
  })
}
onMounted(async () => {
  await store.getList();
  initCharts();
  initPie();
  initLine();
})
</script>

<style lang="less">
* {
  margin: 0;
  padding: 0;
}

html,
body,
#app {
  height: 100%;
  overflow: hidden;
}

@itemColor: #41b0db;
@itemBg: #223651;
@itemBorder: #212028;

.box {
  height: 100%;
  display: flex;
  overflow: hidden;
  // align-items: center; /* 垂直居中 */
  // justify-content: center; /* 水平居中 */

  &-left {
    width: 400px;
  
    &-pie {
      height: 320px;
      margin-top: 20px;
    }

    &-line {
      height: 320px;
      margin-top: 20px;
    }

    // background: red;
    &-card {
      display: grid;
      grid-template-columns: auto auto auto;
      grid-template-rows: auto auto;

      section {
        background: @itemBg;
        border: 1px solid @itemBorder;
        padding: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: white;

        div:nth-child(2) {
          color: @itemColor;
          padding: 10px;
          font-size: 20px;
          font-weight: bold;
        }

      }
    }
  }

  &-center {
    flex: 1;
  }

  &-right {
    width: 400px;
    // background: blue;
  }
}

.table {
  width: 100%;
  background: #212028;
  border: 1px solid #000;

  tr {
    th {
      padding: 5px;
      white-space: nowrap;
    }

    td {
      padding: 5px 10px;
      width: 100px;
      white-space: nowrap;
    }
  }
}
</style>